
package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TEfficAccessRecords;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TAccessRecordsMapper;
import com.ruoyi.system.mapper.TEfficAccessRecordsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TWorkOrderMapper;
import com.ruoyi.system.domain.TWorkOrder;
import com.ruoyi.system.service.ITWorkOrderService;

/**
 * 投放Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@Service
public class TWorkOrderServiceImpl implements ITWorkOrderService 
{
    @Autowired
    private TWorkOrderMapper tWorkOrderMapper;
    @Autowired
    private TAccessRecordsMapper tAccessRecordsMapper;
    @Autowired
    private TEfficAccessRecordsMapper tEfficAccessRecordsMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询投放
     * 
     * @param id 投放主键
     * @return 投放
     */
    @Override
    public TWorkOrder selectTWorkOrderById(Long id)
    {
        return tWorkOrderMapper.selectTWorkOrderById(id);
    }

    /**
     * 查询投放列表
     * 
     * @param tWorkOrder 投放
     * @return 投放
     */
    @Override
    public List<TWorkOrder> selectTWorkOrderList(TWorkOrder tWorkOrder)
    {
        List<TWorkOrder> tWorkOrders = tWorkOrderMapper.selectTWorkOrderList(tWorkOrder);
        if (!tWorkOrders.isEmpty()){
            for (TWorkOrder workOrder : tWorkOrders) {
                workOrder.setSysUser(sysUserMapper.selectUserById(workOrder.getUid()));
                workOrder.setView(tAccessRecordsMapper.countBywWrkOrderId(workOrder.getId(),null));
                workOrder.seteView(tEfficAccessRecordsMapper.countBywWrkOrderId(workOrder.getId(),null));
                workOrder.setViewNow(tAccessRecordsMapper.countBywWrkOrderId(workOrder.getId(),1));
                workOrder.seteViewNow(tEfficAccessRecordsMapper.countBywWrkOrderId(workOrder.getId(),1));
            }
        }
        return tWorkOrders;
    }

    /**
     * 新增投放
     * 
     * @param tWorkOrder 投放
     * @return 结果
     */
    @Override
    public int insertTWorkOrder(TWorkOrder tWorkOrder)
    {
        tWorkOrder.setCreateTime(DateUtils.getNowDate());
        return tWorkOrderMapper.insertTWorkOrder(tWorkOrder);
    }

    /**
     * 修改投放
     * 
     * @param tWorkOrder 投放
     * @return 结果
     */
    @Override
    public int updateTWorkOrder(TWorkOrder tWorkOrder)
    {
        tWorkOrder.setUpdateTime(DateUtils.getNowDate());
        return tWorkOrderMapper.updateTWorkOrder(tWorkOrder);
    }

    /**
     * 批量删除投放
     * 
     * @param ids 需要删除的投放主键
     * @return 结果
     */
    @Override
    public int deleteTWorkOrderByIds(Long[] ids)
    {
        return tWorkOrderMapper.deleteTWorkOrderByIds(ids);
    }

    /**
     * 删除投放信息
     * 
     * @param id 投放主键
     * @return 结果
     */
    @Override
    public int deleteTWorkOrderById(Long id)
    {
        return tWorkOrderMapper.deleteTWorkOrderById(id);
    }
}
